#!/usr/bin/env python
#coding=utf-8
#system default setting
import TAGModule

import os
import sys

#system default setting
reload(sys)
sys.setdefaultencoding('utf-8')

class Match:
	def __init__(self, filteredKeywordList, tagIndexList):
		self.__filteredKeywordList = filteredKeywordList
		self.__tagIndexList = tagIndexList
		self.__tagInform = TAGModule.TagInform()
		#the information in self.__matchedTagIndexList contain the list of tag's name and the tag's Id
		self.__matchedTagIndexList = []

		#the information in self.__matchedTagInformList contaion the list of tag's all information, inclued the tag_id, tag_name, tag_fullId, etc
		self.__matchedTagInformList = []

		#the information in self.__showedTagInformList contaion the list of tag_id, tag_name and the ontology name 
		self.__showedTagInformList = []

	#this is the method which usesd for matching the correct tags with keyword that was extracted before
	def matchKeyword(self):
		for keyword in self.__filteredKeywordList:
			for tagIndex in self.__tagIndexList:
				if tagIndex.getTagName().find(keyword) != -1: 
					self.gainMatchedTagIndexList(tagIndex)
					break

	def gainMatchedTagIndexList(self, tagIndex):
		self.__matchedTagIndexList.append(tagIndex)


	def gainMatchedTagInformList(self, DATPath):
		self.__matchedTagInformList = self.__tagInform.constructAndGainMatchedTagList(self.__matchedTagIndexList, DATPath)

	def gainShowedTagInformList(self, ontologyDic):
		self.__showedTagInformList = self.__tagInform.constrcutShowedTagList(ontologyDic)
		"""
		for showedTag in self.__showedTagInformList:
			print showedTag.getShowedTagName()
		"""


	def getMatchedTagIndexList(self):
		return self.__matchedTagIndexList

	def getMatchedTagInformList(self):
		return self.__matchedTagInformList

	def getShowedTagInformList(self):
		return self.__showedTagInformList


	def showMatchedTagIndexList(self):
		for matchedTagIndex in self.__matchedTagIndexList:
			print matchedTagIndex.getTagName()

	def showMatchedTagInformList(self):
		for matchedTagInform in self.__matchedTagInformList:
			print matchedTagInform

	def showShowedTagInformList(self):
		for showedTagInform in self.__showedTagInformList:
			print showedTagInform.getShowedTagId() + "\t" + showedTagInform.getShowedTagName() + "\t" + showedTagInform.getOntologyName()
